#pragma once
#ifdef WIN32
#pragma comment( lib, "ws2_32.lib" )
#include <winsock2.h>
#include <stdio.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <string>

#if defined WIN32
typedef int socklen_t;
#elif defined __linux__
typedef int SOCKET;
typedef int DWORD;
#define INVALID_SOCKET -1
#define SOCKET_ERROR   -1
#define closesocket(s) close(s);
#endif

//The following methods are overwrites of the linux versions and are real glue code
//Thus, they are only defined in the Windows version
#ifdef WIN32
void close(int sd);
int read (int sd, char* buf, int len);
int write (int sd, const char* buf, int len);
void sleep(long duration_in_seconds);
void printWindowsSocketError();
#endif

//This methods needs to be called if the library shall be used. Since the implementation
//uses #ifdef, it is not needed to check the OS. This leads to clean and #ifdef free code 
//in the client. As a rule: always call this method once as an initialization if you want to use
// sockets in your application.
void startWin32();
void stopWin32();
std::string read_socket(int sd);



